<?php
class classify extends common{
	private $companies_table = "companies";
	private $companies_detail_title_table = "companies_detail_title";
	private $companies_detail_table = "companies_detail";
	private $companies_level_table = "companies_level";
	private $companies_class_table = "companies_trade";
	private $companies_category_table = "companies_categories";
	//显示一级分类
	function getFirst($param){
		    extract($param);
			$sql=$this->companies_category_table." where level=1";
			$result=$this->getList($sql);
			return $result;
	}
	//显示二级分类
	function getSecond($param){
		    extract($param);
			if($id!=="" && $id!==null && $level=2){
				$sqls=$this->companies_category_table." where upid=$id and level=$level";
				$res=$this->getList($sqls);
				if($res['result']!==null && $res['result']!==''){
				return $res;
				}else{
					$msg="没有数据";
					$error="1";
					return array('msg'=>$msg,'error'=>$error);
				}
			}	
	}
	//显示三级分类
	function getThird($param){
		    extract($param);
			if($id!=="" && $id!==null && $level=3){
				//获取公司的名称 星级
				$sql=$this->companies_category_table." t left join ".$this->companies_table." c on t.sort=c.upid where t.id=$id and c.level_id=$level";
				$res=$this->getList($sql, $key="c.title,c.star,c.id,c.img",$num,$page);
				if(is_array($res['result'])){
					foreach($res['result'] as $k=>$v){
						$sql = $this->companies_detail_table." d
								left join ".$this->companies_detail_title_table." t on d.title_id=t.id
								where d.company_id='".$v['id']."'";
						$info = $this->getList($sql,'t.id_marking,d.content');
						if(is_array($info['result'])){
							foreach($info['result'] as $key=>$val){
								$v[$val['id_marking']] = $val['content'];
							}
						}

						$res['result'][$k] = $v;
					}
				}
				if($res['result']!==null && $res['result']!==''){
					return $res;	
				}else{
					$msg="没有数据";
					$error="2";
					return array('msg'=>$msg,'error'=>$error);
				}
			}	
	}
	
	
}
?>
